<template>
  <div class="icons">
    <swiper>
      <swiper-slide v-for="(page, index) in pages" :key="index">
        <div class="icon" v-for="icon in page" :key="icon.id">
          <div class="icon-img">
            <img class="icon-img-content" :src="icon.imgUrl">
          </div>
          <p class="icon-desc">{{icon.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  props: {
    list: Array
  },
  computed: {
    pages () {
      const resPages = []
      this.list.forEach((icon, index) => {
        let page = Math.floor(index / 8)
        if (!resPages[page]) {
          resPages[page] = []
        }
        resPages[page].push(icon)
      })

      return resPages
    }
  }
}
</script>

<style lang='stylus' rel='stylesheet/stylus' scoped>
  @import '~styles/varibles.styl'
  @import '~styles/mixins.styl'
  .icons
    overflow hidden
    height 0
    margin-top .1rem
    padding-bottom 50%
    .icon
      position relative
      float left
      overflow hidden
      width 25%
      height 0px
      padding-bottom 25%
      .icon-img
        position absolute
        top 0px
        left 0px
        right 0px
        bottom .44rem
        box-sizing border-box
        padding .1rem
        .icon-img-content
          display block
          margin 0 auto
          height 100%
      .icon-desc
        position absolute
        left 0px
        right 0px
        bottom 0px
        height .44rem
        line-height .44rem
        text-align center
        color $darkTextContent
        ellipsis()
</style>
